import java.awt.*;
import java.util.*;
import java.awt.event.*;

/**
 * @author Jesse
 *
 */
public class GUI_Frame extends Frame 
{
	public Choice combobox = new Choice();
	public TextField t1, t2;
	public Button b1;
	public Label l1, l2, l3, errorlabel;
	public TextArea ta1;
	public Panel p1, p2, p3;
	public Vector hosts;
	public Control control;
	
	public GUI_Frame(Vector hosts, Control control)
	{	
		this.control = control;
		this.hosts = hosts;
		p1 = new Panel();
		p2 = new Panel();
		p3 = new Panel();
		this.setTitle("Diagnostic Webserver");
		
		for (Iterator i = hosts.iterator(); i.hasNext();)
		{
			String j = (String)i.next();
			combobox.addItem(j);
		}
		
		
		combobox.addItemListener(control);
		l1 = new Label("host = ");
		l2 = new Label("port = ");
		l3 = new Label("codebase = ");
		errorlabel = new Label();
		errorlabel.setForeground(Color.red);
		b1 = new Button("Start");
		b1.setBackground(Color.GREEN);
		b1.addActionListener(control);
		ta1 = new TextArea();
		ta1.setEditable(false);
		ta1.setPreferredSize(new Dimension(700, 480));
		t1 = new TextField("8080", 10);
		t2 = new TextField(10);
		t1.addFocusListener(control);
		t2.addFocusListener(control);
		this.setLayout(new BorderLayout());
		
		
		p1.add(l1); p1.add(combobox);
		p1.add(l2); p1.add(t1);
		p1.add(l3); p1.add(t2);
		p1.add(b1);
		this.add(p1, BorderLayout.NORTH);
		
		p2.add(ta1); p3.add(errorlabel);
		this.add(p2, BorderLayout.CENTER);
		this.add(p3, BorderLayout.SOUTH);
		this.setSize(new Dimension(800,600));
		this.setVisible(true);
		this.addWindowListener(control);
	}
	
	public void setText(String string)
	{	
		String text;
		text = ta1.getText() + string;
		ta1.setText(text);
	}
	
	public void setError(String string)
	{
		errorlabel.setText(string);
	}
	public void flipButton(){
		if (b1.getLabel() == "Start"){
			b1.setBackground(Color.RED);
			b1.setLabel("Stop");
		}else{
			b1.setBackground(Color.GREEN);
			b1.setLabel("Start");
		}
		
	}
	
}
